package com.byp.java_sport.exception;


import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import com.byp.java_sport.model.Result;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(value = NotLoginException.class)
    public Result<String> handler(NotLoginException e, HttpServletRequest request) {
        log.error("SaToken鉴权异常----------url:{}", request.getRequestURI(),e);
        return Result.error(401,"系统异常",request.getRequestURI());
    }
    @ExceptionHandler(value = NotPermissionException.class)
    public Result<String> handler(NotPermissionException e, HttpServletRequest request) {
        log.error("SaToken鉴权异常----------url:{}", request.getRequestURI(),e);
        return Result.error(403,e.getMessage(),request.getRequestURI());
    }
}
